package com.twu.biblioteca.user;

import com.twu.biblioteca.utils.IdDriver;

/**
 * Created by Enrico on 17/09/2014.
 */
public class Account {

    private String libraryNo;
    private String password;

    private static final String LIBRARY_NO_PREFIX = "A00-";

    private static final String PASSWORD_PREFIX = "enrico";

    public Account() {
        String uniqueNumber = generateUniqueNumber();
        libraryNo = LIBRARY_NO_PREFIX + uniqueNumber;
        password = PASSWORD_PREFIX + uniqueNumber;
    }

    public Account(String libraryNo, String password) {
        this.libraryNo = libraryNo;
        this.password = password;
    }

    public boolean login(String libraryNo, String password) {
        return matchesLibraryNo(libraryNo) && matchesPassword(password);
    }

    public boolean matchesLibraryNo(String libraryNo) {
        return this.libraryNo.equals(libraryNo);
    }

    public boolean matchesPassword(String password) {
        return this.password.equals(password);
    }

    public String generateUniqueNumber() {
        return String.format("%04d", IdDriver.getUniqueId());
    }
}
